#include "signalhandler.hpp"
#include "logger.hpp"
#include <csignal>

namespace oraysock5 {
void SignalHandler::add(std::shared_ptr<EventBase> base,
    int sig, callback cb)
{
    std::shared_ptr<SignalEvent> se = std::make_shared<SignalEvent>(base, sig, cb);
    base->addevent(se, nullptr);
    sigevents_[sig] = se;
}

SignalHandler::SignalEvent::SignalEvent(std::shared_ptr<EventBase> base,
    int sig, callback cb)
    : EventHandler(base, sig, EV_SIGNAL | EV_PERSIST)
{
    cb_ = cb;
}

void SignalHandler::SignalEvent::signal(int signal)
{
    cb_(base(), signal);
}
}
